#ifndef REPOSITORY_H_
#define REPOSITORY_H_


#include <iostream>
#include <fstream>
#include <map>
#include "./md5/md5wrapper.h"  // ver http://www.md5hashing.com/algorithm/



#include "../classes_teste/Estatistica.h"


#include <boost/tr1/memory.hpp>
#include <boost/thread/mutex.hpp>


using namespace std; // temporario

class Repository{
private:
	Repository();		
	
public:
	static std::tr1::shared_ptr<Repository> getInstance() {return theRepository;}
	~Repository();
	void store(string _url, string _page);
	void oldStore(string _url, string _page);
	void newOldStore(string _url, string _page);
	int size(void);
	string getPage(string _url);
private:
	bool isEmpty(string hash);
	string hash_key(string _url);
	md5wrapper md5;
	map<string,string> mapa;
	map<string,string>::iterator it;
	//ofstream fileToDisk;

	FILE * fileToDisk[32];
	
	static int numStores;
	
	//Apenas 1 copia
	 static std::tr1::shared_ptr<Repository> theRepository;
	 static boost::mutex storeMutex;
	
     //para estatistica
     static unsigned long int contador;
     Estatistica contadorPaginas;

};

#endif /*REPOSITORY_H_*/
